package com.water.camera.fragment;

import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.plata.base.utils.WeakHandler;

public class BaseFragment extends Fragment {

    protected WeakHandler h = new WeakHandler();

//    protected void showLoading() {
//        try {
//            ((BaseActivity) getActivity()).showLoading();
//        } catch (Throwable e) {
//            e.printStackTrace();
//        }
//    }
//
//    protected void hideLoading() {
//        try {
//            ((BaseActivity) getActivity()).hideLoading();
//        } catch (Throwable e) {
//
//        }
//    }
//
//    protected boolean isLoading() {
//        try {
//            return ((BaseActivity) getActivity()).isLoading();
//        } catch (Throwable e) {
//            return false;
//        }
//    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        h.removeCallbacksAndMessages(null);
    }

    public void replaceFragment(int id, Fragment fragment) {
        try {
            FragmentTransaction transaction = getChildFragmentManager().beginTransaction();
            transaction.replace(id, fragment);
            transaction.commitAllowingStateLoss();
        } catch (Throwable e) {
            e.printStackTrace();
        }
    }
}
